// 引入定义小仓库的方法
import { defineStore } from "pinia";
// 引入医院相关的 api 
import { reqHospitalDetail, reqHospitalDepartment } from "@/api/hospital";
// 引入医院相关数据的 type
import { HospitalDetail, HospitalDetailData, DepartmentArr, DepartmentData } from "@/api/hospital/type";
// 引入 state 维护的数据的类型
import { DetailType } from "./interface";

const useDetailStore = defineStore("Detail", {
    state: (): DetailType => {
        return {
            // 医院详情的数据
            hospitalInfo: {} as HospitalDetail,

            // 医院科室数据 
            departmentInfo: [] as DepartmentArr
        }
    },
    actions: {
        // 获取医院详情的方法
        async getHospital(hoscode: string) {
            let result: HospitalDetailData = await reqHospitalDetail(hoscode);
            if (result.code === 200) {
                this.hospitalInfo = result.data;
            }
        },

        // 获取医院科室的方法
        async getDepartment(hoscode: string) {
            let result: DepartmentData = await reqHospitalDepartment(hoscode);
            if (result.code === 200) {
                this.departmentInfo = result.data;
            }
        }
    },
    getters: {

    }
});

// 暴露仓库
export default useDetailStore